package com.shj.em.biz.report.dto;

import com.shj.em.biz.Constants;
import lombok.Data;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;

@Data
public class GrowRatioDTO {

    List<Integer> currentYearTarget; // 已经是万元为单位了

    List<BigDecimal> lastYearActual;

    List<BigDecimal> currentYearActual;

    List<Integer> currentYearAccumTarget; // 已经是万元为单位了

    List<BigDecimal> lastYearAccumActual;

    List<BigDecimal> currentYearAccumActual;

    List<String> finishRate;



    public void calcFinishRate(){
        finishRate = new ArrayList<>();
        for(int i = 0; i < currentYearAccumActual.size(); i++){
            BigDecimal val = currentYearAccumActual.get(i).multiply(Constants.hundred).divide(new BigDecimal(currentYearAccumTarget.get(i)), 2, RoundingMode.HALF_UP);
            finishRate.add(val.toPlainString() + "%");
        }
    }

    // 转化成万元为单位
    public void convert(){
        convertTo(lastYearActual);
        convertTo(currentYearActual);
        convertTo(lastYearAccumActual);
        convertTo(currentYearAccumActual);
    }

    public static void convertTo(List<BigDecimal> list){
        for(int i = 0 ; i < list.size(); i++){
            BigDecimal bd = list.get(i);
            list.set(i, bd.divide(Constants.wan, 2, RoundingMode.HALF_UP));
        }
    }
}
